import { Body, Controller, Post } from '@nestjs/common';
import { BookingService } from './booking.service';
import { ListBookDto } from './dto/list-book.dto';
import { AddBookDto } from './dto/add-book.dto';
import { RequireLogin } from 'src/custom.decorator';

@Controller('book')
export class BookingController {
  constructor(private readonly bookingService: BookingService) {}
  @Post('initData')
  async initData() {
    return await this.bookingService.initData();
  }
  @RequireLogin()
  @Post('list')
  async list(@Body() listBookDto: ListBookDto) {
    return await this.bookingService.list(listBookDto);
  }
  @Post('add')
  @RequireLogin()
  async add(@Body() addBookDto: AddBookDto) {
    return this.bookingService.add(addBookDto);
  }
  @Post('update')
  async update(@Body() addBookDto: AddBookDto & { id: number }) {
    return this.bookingService.updateById(addBookDto);
  }
  @RequireLogin()
  @Post('delete')
  async deleteById(@Body() id: { id: number }) {
    return this.bookingService.deleteById(id.id);
  }
}
